import java.io.*;
import java.text.DecimalFormat;

public class h_6 implements Runnable {
    String file;
    public h_6(String file){
        this.file=file;
    }
    @Override
    public void run() {
        FileInputStream fis=null;
        FileOutputStream fos = null;
        try {
            File filename=new File(file);
            fis=new FileInputStream(filename);
            fos=new FileOutputStream("copy"+file);
            long sum=filename.length();
            double get=0.0;
            int ch=0;
            DecimalFormat fd = new DecimalFormat("##.#%");
            while((ch=fis.read())!=-1){
                fos.write(ch);
                get=get+1;
                /*if(((double)get/(double)sum)*100%10==0){
                    System.out.println(file+"文件复制了"+((double)get/(double)sum)*100+"%");
                }*/
                double a=get/sum;
                System.out.println(file+"文件复制了"+fd.format(a));
            }
            System.out.println(file+"文件复制完成");

        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
